package com.example.demo.quartz;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @description:
 * @author: cj
 * @create: 15-08-01 15:54:18
 */
@Component
@Slf4j
public class ScheduleTest {
    @Scheduled(cron = "*/2 * * * * ?")
    public void task1() throws InterruptedException {
        log.error ( "我是task1111，我需要执行 10s 钟的时间，我的线程的 id == > {}，时间 == >{}", Thread.currentThread ().getId (), new Date () );
        Thread.sleep ( 10000 );
        log.error ( "task1111 ending ,我的线程的 id == > {} , 时间 == > {}", Thread.currentThread ().getId (), new Date () );
    }

    @Scheduled(cron = "*/4 * * * * ?")
    public void task2() throws InterruptedException {
        log.error ( "我是task2222，我需要执行 2s 钟的时间，我的线程的 id == > {}，时间 == >{}", Thread.currentThread ().getId (), new Date () );
        Thread.sleep ( 2000 );
        log.error ( "task2222 ending ,我的线程的 id == > {} , 时间 == > {}", Thread.currentThread ().getId (), new Date () );
    }
}
